<?php

class AnswerControl extends Control {

    public function index() {
        $where = (int) $_GET['anwhere'];
        switch ($where) {
            case 0:
                $sql = 'SELECT * FROM hd_answer';
                $sql2 = 'SELECT count(*) as c FROM hd_answer';
                break;
            case 1:
                $sql = 'SELECT * FROM hd_answer where accept=0';
                $sql2 = 'SELECT count(*) as c FROM hd_answer  where accept=0';
                break;
            case 2:
                $sql = 'SELECT * FROM hd_answer where accept=1';
                $sql2 = 'SELECT count(*) as c FROM hd_answer  where accept=1';
                break;
        }
        $data = M('answer')->query($sql);
        $this->assign('data', $data);
        $data2 = M('answer')->query($sql2);
        $this->assign('data2', $data2[0]['c']);
        $this->display();
    }

    public function del() {
        $anid = (int) $_GET['anid'];
        if (M('ask')->exec('DELETE FROM hd_answer where anid=' . $anid)) {
            $this->error('删除成功！');
        } else {
            $this->error('删除失败！');
        }
    }

}
